<template>
	<div>
		<p>查看库存:商品名称:
			<select v-model="productId">
				<option value="0">请选择</option>
				<option v-for="item in ProductList" :value='item.id'>{{item.productName}}</option>
			</select>
			<button @click="getAllProductById()">查询</button>
		</p>
		<h2 v-show="show=='1'">
			该商品的库存为:{{product.quantity}}
		</h2>
	</div>
</template>

<script>
	import axios from 'axios'
	export default{
		data(){
			return{
				ProductList:[],
				product:[],
				productId:"0",
				show:0
			}
		},
		beforeCreate() {
			var that=this;
			var url="http://localhost:8080/getAllProduct";
			axios.get(url,{
				params:{
					
				}
			}).then(res=>{
					that.ProductList=res.data.data;			
			})
		},
		methods:{
			getAllProductById:function(){
				this.show=1;
				var that=this;
				var url="http://localhost:8080/getAllProductById";
				axios.get(url,{
					params:{
						id:that.productId
					}
				}).then(res=>{
						that.product=res.data.data;			
				})
			}
		}
	}
</script>

<style>
</style>
